package com.study.spmongodb.wwj.thread2.char05;

/**
 * @author MI
 * @version 1.0
 * @date 2020/12/7 21:21
 * SharedResource
 * 临界值
 */
public class Gate {

    private int count = 0;

    private String name = "Nobody";

    public String address = "Nowhere";

    public /*synchronized*/ void pass(String name, String address) {
        this.count++;
        this.name = name;
        this.address = address;
        verify();
    }

    private void verify() {
        if (this.name.charAt(0) != this.address.charAt(0)) {
            System.out.println("-----broken---------" + toString());
        }
    }

    @Override
    public String toString() {
        return "No " + count + " name: " + name + " , " + address;
    }
}
